package org.apache.ibatis.common.logging.log4j;

import org.apache.ibatis.common.logging.Log;
import org.apache.ibatis.common.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * @Name Log4jImpl
 * @Description: [log4j 日志框架] 实现类
 * 描述信息：该类是一个典型的对象适配器。
 * 它的内部持有一个 “org.apache.log4j.Logger” 对象，所有方法都将操作委托了给该对象。
 * @Version v1.0.0
 * @Author: lichao
 * @Date: 2024-05-15 15:33:56
 **/
public class Log4jImpl implements Log {
    private static final String FQCN = Log4jImpl.class.getName();
    private final Logger log;

    public Log4jImpl(String clazz) {
        this.log = Logger.getLogger(clazz);
    }

    @Override
    public boolean isDebugEnabled() {
        return log.isDebugEnabled();
    }

    @Override
    public boolean isTraceEnbaled() {
        return log.isTraceEnabled();
    }

    @Override
    public void error(String msg, Throwable e) {
        log.log(FQCN, Level.ERROR, msg, e);
    }

    @Override
    public void error(String msg) {
        log.log(FQCN, Level.ERROR, msg, null);
    }

    @Override
    public void warn(String msg) {
        log.log(FQCN, Level.WARN, msg, null);
    }

    @Override
    public void debug(String msg) {
        log.log(FQCN, Level.DEBUG, msg, null);
    }

    @Override
    public void trace(String msg) {
        log.log(FQCN, Level.TRACE, msg, null);
    }

}

